package com.example.mystoryapp2.ui.utils

import android.app.Activity
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentActivity
import com.example.mystoryapp2.contexts.AppContext
import com.example.mystoryapp2.ui.main.MainActivity
import com.example.mystoryapp2.ui.user.login.LoginActivity

object UserInfoUtils {
    fun backToLogin(activity: AppCompatActivity) {
        AppContext.clearJwt()
        val intent = Intent(activity, LoginActivity::class.java)
        activity.startActivity(intent)
        activity.finish()
    }

    fun backToLogin(activity: FragmentActivity) {
        AppContext.clearJwt()
        val intent = Intent(activity, LoginActivity::class.java)
        activity.startActivity(intent)
        activity.finish()
    }

    fun afterLoginSuccess(jwt: String?, context: Activity? = null) {
        val intent = Intent(context, MainActivity::class.java)
        if (context == null) {
            AppContext.application.baseContext.startActivity(intent)
        } else {
            context.startActivity(intent)
            context.finish()
        }
    }
}